const fs = require('fs');

module.exports = function (req, res, next) {
  const canvasImageDataURL = req.body.canvasImage;
  const section = req.body.section;
  const template = req.body.template;
  // 将Canvas图像数据保存到本地
  const canvasImageBuffer = Buffer.from(canvasImageDataURL.split(',')[1], 'base64');
  fs.writeFileSync(`./src/theme/${template}/assets/${section}.jpg`, canvasImageBuffer, 'base64');
  res.json({ data: '' }).end();
};
